package com.gxhmplan.cases.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gxhmplan.cases.dao.CaseDao;
import com.gxhmplan.cases.entity.Case;

@Service("caseService")
public class CaseServiceImpl implements CaseService {
	@Resource
	CaseDao caseDao;

	public int addCase(Case c) {
		c.setId(UUID.randomUUID().toString());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		c.setCreateTime(sdf.format(new Date()));
		c.setBrowse(0);
		return caseDao.addCase(c);
	}

	public List<Map<String, Object>> findCase() {
		return caseDao.findCase();
	}

	public int deleteCaseById(String id) {
		return caseDao.deleteCaseById(id);
	}

	public List<Map<String, Object>> findCaseByClassify(String classify) {
		return caseDao.findCaseByClassify(classify);
	}

	public Case findCaseById(String id) {
		Case cases = caseDao.findCaseById(id);
		HashMap<String,Object> map = new HashMap<String,Object>();
		Integer browse = cases.getBrowse();
		System.out.println(cases);
		if (browse==null) {
			browse = 0;
		}
		map.put("id", cases.getId());
		map.put("browse", browse+1);
		caseDao.updateBrowse(map);
		return cases;
	}

	public Case findCaseByCaseNum(String caseNum) {
		return caseDao.findCaseByCaseNum(caseNum);
	}

	public Case findFrontCaseById(String id) {
		return caseDao.findFrontCaseById(id);
	}

	public Case findAfterCaseById(String id) {
		return caseDao.findAfterCaseById(id);
	}
}
